<?php

namespace App\Http\Requests\Admin\Store;

use App\Http\Requests\ApiRequest;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;

/**
 * @property int is_sale
 * @property int is_deleted
 * @property int is_hot
 * @property int is_new
 * @property string brand_id
 * @property string category_id
 * @property string keyword
 * @property string sort_column
 * @property string sort_by
 * @property string $product_type
 * @property string $has_youzan
 */
class ProductIndexRequest extends ApiRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        return [
            'keyword'     => ['nullable', 'string'],
            'brand_id'    => 'nullable|int|min:1',
            'category_id' => 'nullable|int|min:1',
            'is_sale'     => ['nullable', 'int', Rule::in([0, 1])],
            'is_deleted'  => ['nullable', 'int', Rule::in([0, 1])],
            'is_hot'      => ['nullable', 'int', Rule::in([0, 1])],
            'is_new'      => ['nullable', 'int', Rule::in([0, 1])],
        ];
    }

    /**
     * @return array
     */
//    public function messages()
//    {
//        return [
//            'keyword.*'     => '产品标题必须是字符串',
//            'brand_id.*'    => '产品品牌编号必须是数值',
//            'category_id.*' => '产品类别id必须是数值',
//            'is_sale.*'     => '是否出售中的值必须是0或1',
//            'is_deleted.*'  => '是否删除的值必须是0或1',
//            'is_hot.*'      => '是否热销的值必须是0或1',
//            'is_new.*'      => '是否新品的值必须是0或1'
//        ];
//    }
}
